import React from 'react';
import { Button, message, Modal } from 'antd';
import axios from '@/components/service/request';

const DeleteButton = ({ record, onDelete }) => {
    const handleDelete = () => {
        Modal.confirm({
            title: '确认删除',
            content: '您确定要删除该文件吗？此操作无法撤销。',
            okText: '确认',
            cancelText: '取消',
            onOk() {
                // 执行删除操作
                axios.post('/filedata/delete', null, {
                    params: { filePath: record.filePath }
                })
                .then(() => {
                    message.success('删除成功');
                    onDelete(record.filePath);  // 通知父组件，传递文件名
                })
                .catch(error => {
                    console.error('Error deleting record:', error);
                    message.error('删除失败');
                });
            },
        });
    };

    return (
        <Button onClick={handleDelete} danger>
            删除
        </Button>
    );
};

export default DeleteButton;
